// 账号密码对列表
const userCredentials = [
  { username: 'user1', password: '38492017' },
  { username: 'user2', password: '58210394' },
  { username: 'user3', password: '76049281' },
  { username: 'user4', password: '19583746' },
  { username: 'user5', password: '82037465' },
  { username: 'user6', password: '43920185' },
  { username: 'user7', password: '91827364' },
  { username: 'user8', password: '27491836' },
  { username: 'user9', password: '65019283' },
  { username: 'user10', password: '83746520' },
  { username: 'user11', password: '49281736' },
  { username: 'user12', password: '10394827' },
  { username: 'user13', password: '58274913' },
  { username: 'user14', password: '76018394' },
  { username: 'user15', password: '91820473' },
  { username: 'user16', password: '38475629' },
  { username: 'user17', password: '65091827' },
  { username: 'user18', password: '27463918' },
  { username: 'user19', password: '10385749' },
  { username: 'user20', password: '49283617' },
  { username: 'user21', password: '83749210' },
  { username: 'user22', password: '91837465' },
  { username: 'user23', password: '58210397' },
  { username: 'user24', password: '76049213' },
  { username: 'user25', password: '19583749' },
  { username: 'user26', password: '82037469' },
  { username: 'user27', password: '43920187' },
  { username: 'user28', password: '91827369' },
  { username: 'user29', password: '27491839' },
  { username: 'user30', password: '65019287' },
  { username: 'user31', password: '83746529' },
  { username: 'user32', password: '49281739' },
  { username: 'user33', password: '10394829' },
  { username: 'user34', password: '58274919' },
  { username: 'user35', password: '76018397' },
  { username: 'user36', password: '91820479' },
  { username: 'user37', password: '38475621' },
  { username: 'user38', password: '65091829' },
  { username: 'user39', password: '27463919' },
  { username: 'user40', password: '10385741' },
  { username: 'user41', password: '49283619' },
  { username: 'user42', password: '83749213' },
  { username: 'user43', password: '91837469' },
  { username: 'user44', password: '58210391' },
  { username: 'user45', password: '76049219' },
  { username: 'user46', password: '19583741' },
  { username: 'user47', password: '82037461' },
  { username: 'user48', password: '43920189' },
  { username: 'user49', password: '91827361' },
  { username: 'user50', password: '27491831' }
];

function validateLogin(username, password) {
  return userCredentials.some(
    (cred) => cred.username === username && cred.password === password
  );
}

Page({
  data: {
    account: '',
    password: ''
  },
  onLoad() {
    // 页面加载时尝试读取本地账号密码
    const accountValue = wx.getStorageSync('account') || '';
    const passwordValue = wx.getStorageSync('password') || '';
    this.setData({"account":accountValue, "password":passwordValue});
    console.log('已填充账号，密码');
  },
  onAccountInput(e) {
    this.setData({ account: e.detail.value });
  },
  onPasswordInput(e) {
    this.setData({password: e.detail.value });
  },
  onLogin() {
    const { account, password } = this.data;
    if (!account || !password) {
      wx.showToast({ title: '请输入账号和密码', icon: 'none' });
      return;
    }
    if (validateLogin(account, password)) {
      wx.setStorageSync('account', account);
      wx.setStorageSync('password', password);
      wx.showToast({ title: '登录成功', icon: 'success' });
      wx.switchTab({ url: '/pages/index/index' });
    } else {
      wx.showToast({ title: '账号或密码错误', icon: 'none' });
    }
  }
}); 